package com.wuhongyu.controller;

import com.wuhongyu.entity.Plan;
import com.wuhongyu.service.PlanService;
import com.wuhongyu.service.ReferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 开发计划
 */
@Controller
@RequestMapping("/plan")
public class PlanController {

    @Autowired
    private ReferService referService;
    @Autowired
    private PlanService planService;

    /**
     * 不需要分页,也不需要条件查询,只需要referid
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model,Integer referid){
       model.addAttribute("planList",planService.findByRefer(referid));
       model.addAttribute("refer",referService.findOne(referid));
       return "~sale/dev_plan";
    }

    @RequestMapping("/save")
    public String save(Model model,Plan plan){
        planService.save(plan);
        if(plan.getResult()!=null){
            return this.execute(model,plan.getRefer().getId());
        }
        return this.list(model,plan.getRefer().getId());
    }

    @RequestMapping("/delete")
    public String delete(Model model,Integer id){
        Plan plan = planService.findOne(id);
        planService.delete(id);
        return this.list(model,plan.getRefer().getId());
    }

    /**
     * 执行计划
     * @param model
     * @param referid
     * @return
     */
    @RequestMapping("/execute")
    public String execute(Model model,Integer referid){
        model.addAttribute("planList",planService.findByRefer(referid));
        model.addAttribute("refer",referService.findOne(referid));
        return "~sale/dev_execute";
    }


}